#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e3 + 10;
ll a[N];
ll n;
ll dp[N][N];
void solve()
{
    ll sum = 0;
    cin >> n;
    for (ll i = 1; i <= n;i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    //初始化
    for (ll i = 1; i <= n;i++)
        dp[i][i] = 0;
    for (ll i = 1; i < n;i++)
    {
        dp[i][i + 1] = min(a[i], a[i + 1]);
    }

    //转移方程
    for (int l = 3; l <= n; ++l)
    {
        for (int i = 1, j; i + l - 1 <= n; ++i)
        {
            j = i + l - 1;
            if (a[i] >= a[j])
            {
                dp[i][j] = max(dp[i + 2][j] + a[i + 1], dp[i + 1][j - 1] + a[j]);
            }
            else
            {
                dp[i][j] = max(dp[i + 1][j - 1] + a[i], dp[i][j - 2] + a[j - 1]);
            }
        }
    }

    cout << sum - dp[1][n] << " " << dp[1][n];
}
int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}